package com.atguigu.daijia.payment.receiver;

import com.atguigu.daijia.common.constant.MqConst;
import com.atguigu.daijia.payment.service.WxPayService;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

@Component
public class PaymentReceiver {

    @Autowired
    private WxPayService wxPayService;


    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = MqConst.QUEUE_PAY_SUCCESS,durable = "true"),
            exchange = @Exchange(value = MqConst.EXCHANGE_ORDER),
            key = {MqConst.ROUTING_PAY_SUCCESS}
    ))

    //String orderNo：消息体内容（JSON 或纯文本），这里直接当成订单号字符串。
    //Message message：Spring AMQP 封装的消息对象，包含消息属性、头信息等。
    //Channel channel：原生 RabbitMQ 的通道，可用于手动确认消息（ack/nack）。

    public void paySuccess(String orderNo,Message message,Channel channel) throws Exception {
        wxPayService.handleOrder(orderNo);
    }


//    @RabbitListener(bindings = @QueueBinding(
//            value = @Queue(value = MqConst.QUEUE_PAY_SUCCESS,durable = "true"),
//            exchange = @Exchange(value = MqConst.EXCHANGE_ORDER),
//            key = {MqConst.ROUTING_PAY_SUCCESS}
//    ))
//    public void paySuccess(String orderNo, Message message, Channel channel) {
//        wxPayService.handleOrder(orderNo);
//    }
}
